﻿/* 
 * author: www.cnblogs.com/luminji
 * date  : 2012/02/01
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Luminji.Core.Web.Cookie;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Luminji.Core.Web.Mockes;

namespace Luminji.Core.UnitTest.Web.Cookie
{
    [TestClass]
    public class CookieHelperTest
    {
        [TestMethod]
        public void CookieCanSetAndRead()
        {
            HttpContextBase httpContext = MvcMockHelpers.FakeHttpContext();
            var model = new LogOnModelTemp() { Age = 11, Name = "abc" };
            CookieHelper.SetCookieValue<LogOnModelTemp>(httpContext.Response, "LogOnModel", model);
            var expect = CookieHelper.GetCookieValue<LogOnModelTemp>(httpContext.Request, "LogOnModel");
            Assert.AreEqual(model.Age, expect.Age);
            Assert.AreEqual(model.Name, expect.Name);
        }

        [TestMethod]
        public void CookieCanBeCleared()
        {
            HttpContextBase httpContext = MvcMockHelpers.FakeHttpContext();
            var model = new LogOnModelTemp() { Age = 11, Name = "abc" };
            CookieHelper.SetCookieValue<LogOnModelTemp>(httpContext.Response, "LogOnModel", model);
            CookieHelper.DeleteCookieValue(httpContext.Response, "LogOnModel");
            var expect = CookieHelper.GetCookieValue<LogOnModelTemp>(httpContext.Request, "LogOnModel");
            Assert.IsNull(expect);
        }

        public class LogOnModelTemp
        {
            public string Name { get; set; }
            public int Age { get; set; }
        } 
    }
}
